package com.ruoyi.management_controller.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.management_controller.suggestions.domain.Suggestions;
import com.ruoyi.management_controller.suggestions.service.ISuggestionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代表建议Controller
 * 
 * @author ruoyi
 * @date 2024-07-15
 */
@RestController
@RequestMapping("/suggestions/suggestions")
public class SuggestionsController extends BaseController
{
    @Autowired
    private ISuggestionsService suggestionsService;

    /**
     * 查询代表建议列表
     */
    @PreAuthorize("@ss.hasPermi('suggestions:suggestions:list')")
    @GetMapping("/list")
    public TableDataInfo list(Suggestions suggestions)
    {
        startPage();
        List<Suggestions> list = suggestionsService.selectSuggestionsList(suggestions);
        return getDataTable(list);
    }

    /**
     * 导出代表建议列表
     */
    @PreAuthorize("@ss.hasPermi('suggestions:suggestions:export')")
    @Log(title = "代表建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Suggestions suggestions)
    {
        List<Suggestions> list = suggestionsService.selectSuggestionsList(suggestions);
        ExcelUtil<Suggestions> util = new ExcelUtil<Suggestions>(Suggestions.class);
        util.exportExcel(response, list, "代表建议数据");
    }

    /**
     * 获取代表建议详细信息
     */
    //@PreAuthorize("@ss.hasPermi('suggestions:suggestions:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(suggestionsService.selectSuggestionsById(id));
    }

    /**
     * 新增代表建议
     */
    @PreAuthorize("@ss.hasPermi('suggestions:suggestions:add')")
    @Log(title = "代表建议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Suggestions suggestions)
    {
        return toAjax(suggestionsService.insertSuggestions(suggestions));
    }

    /**
     * 修改代表建议
     */
    @PreAuthorize("@ss.hasPermi('suggestions:suggestions:edit')")
    @Log(title = "代表建议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Suggestions suggestions)
    {
        return toAjax(suggestionsService.updateSuggestions(suggestions));
    }

    /**
     * 删除代表建议
     */
    @PreAuthorize("@ss.hasPermi('suggestions:suggestions:remove')")
    @Log(title = "代表建议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(suggestionsService.deleteSuggestionsByIds(ids));
    }
}
